namespace SmartSoft.ADP
{
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Text;

    public class UserDataAccess
    {
        private WSUserDataAccess.WSUserDataAccess wDataAcess = new WSUserDataAccess.WSUserDataAccess();        
        private SmartSoft.DAL.UserDataAccess oDataAcess = new SmartSoft.DAL.UserDataAccess();

        public UserDataAccess()
        {
            wDataAcess.Url = wDataAcess.Url.Replace("localhost", AdapterInstance.ServerIp);
        }

        public string Base64Decode(string ps_String)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.Base64Decode(ps_String);
            }
            else
            {
                return oDataAcess.Base64Decode(ps_String);
            }
        }

        public string Base64Encode(string ps_String)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.Base64Encode(ps_String);
            }
            else
            {
                return oDataAcess.Base64Encode(ps_String);
            }
        }

        public int ChangePassword(long pi_Stt, string ps_Password)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.ChangePassword(pi_Stt, ps_Password);
            }
            else
            {
                return oDataAcess.ChangePassword(pi_Stt, ps_Password);
            }
        }

        public DataSet GetDataSet()
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.GetDataSet();
            }
            else
            {
                return oDataAcess.GetDataSet();
            }
        }

        public DataTable GetTable(string ps_UserName)
        {
            DataTable table = null;
            if (AdapterInstance.IsRemoteConnected)
            {
                table= wDataAcess.GetTable(ps_UserName);
            }
            else
            {
                table= oDataAcess.GetTable(ps_UserName);
            }
            if (table != null) table.TableName = string.Empty;
            return table;
        }

        public string GetUserName(string ps_UserName)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.GetUserName(ps_UserName);
            }
            else
            {
                return oDataAcess.GetUserName(ps_UserName);
            }
        }

        public DataTable GetUserRights(string ps_FuncType, object pi_Usr_GrpID, string ps_Usr_Grp)
        {
            DataTable table = null;
            if (AdapterInstance.IsRemoteConnected)
            {
                table= wDataAcess.GetUserRights(ps_FuncType, pi_Usr_GrpID, ps_Usr_Grp);
            }
            else
            {
                table= oDataAcess.GetUserRights(ps_FuncType, pi_Usr_GrpID, ps_Usr_Grp);
            }
            if (table != null) table.TableName = string.Empty;
            return table;
        }

        public int GetUserType(string ps_UserName)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.GetUserType(ps_UserName);
            }
            else
            {
                return oDataAcess.GetUserType(ps_UserName);
            }
        }

        public void ResetRights(string ps_UserOrGroup, object pi_UserOrder)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                wDataAcess.ResetRights(ps_UserOrGroup, pi_UserOrder);
            }
            else
            {
                oDataAcess.ResetRights(ps_UserOrGroup, pi_UserOrder);
            }
        }

        public void SaveRights(string ps_UserOrGroup, object pi_UserOrder, string ps_FuncType, DataRow row)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                wDataAcess.SaveRights(ps_UserOrGroup, pi_UserOrder, ps_FuncType, SmartSoft.DAL.SSDataAccess.ConvertRowToTable(row));
            }
            else
            {
                oDataAcess.SaveRights(ps_UserOrGroup, pi_UserOrder, ps_FuncType, row);
            }
        }

        public int SaveRow(bool pb_NewChecked, DataRow row)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.SaveRow(pb_NewChecked, SmartSoft.DAL.SSDataAccess.ConvertRowToTable(row));
            }
            else
            {
                return oDataAcess.SaveRow(pb_NewChecked, row);
            }
        }

        public bool UserValidated(string ps_UserName, string ps_Password)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.UserValidated(ps_UserName, ps_Password);
            }
            else
            {
                return oDataAcess.UserValidated(ps_UserName, ps_Password);
            }
        }
    }
}